﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Ccit.Utils
{
    /// <summary>
    /// MD5 算法类
    /// </summary>
    public class MD5Lib
    {
        /// <summary>
        /// 对传入数据进行MD5算法加密
        /// </summary>
        /// <param name="data">传入数据</param>
        /// <returns></returns>
        public static string Encrypt(string data)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] dataArray = System.Text.Encoding.Default.GetBytes(data);
            byte[] result = md5.ComputeHash(dataArray);
            string ret = string.Empty;
            for (int i = 0; i < result.Length; i++)
                    ret += result[i].ToString("x").PadLeft(2, '0');
            return ret;

        }
    }
}
